package com.activenetwork.util.grid.condition;

import java.util.regex.Pattern;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

public class RegexCondition implements Condition {
    private int column;
    private Pattern pattern;
    
	public int getColumn() {
		return column;
	}
	public void setColumn(int column) {
		this.column = column;
	}
	public Pattern getPattern() {
		return pattern;
	}
	public void setPattern(Pattern pattern) {
		this.pattern = pattern;
	}
	/**
	 * Empty constructor
	 */
	public RegexCondition(){
		this.column = -1;
		this.pattern = null;
	}
	/**
	 * Direct constructor
	 * @param column
	 * @param pattern
	 */
	public RegexCondition(int column, Pattern pattern) {
        this.column = column;
        this.pattern = pattern;
    }
	
	@Override
    public boolean matchs(WebElement row) {
        boolean flag = false;
        if (pattern.matcher(row.findElement(By.xpath("./td[" + column + "]")).getText()).matches()) {
            flag = true;
        }
        return flag;
    }
}
